package com.example.protestgps;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.hardware.SensorManager;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

public class MainActivity extends FragmentActivity {

	private LocationManager lm;
	GoogleMap myMap;
	public Context con;
	ArrayList<LatLng> mMarkerPoints = new ArrayList<LatLng>();// add
	public LatLng locationchange;
	public double latchange = 0;
	public double lngchange = 0;
	public LatLng des;
	public int click;
	LatLng start2;
	SensorManager sm;
	Button btnemegency;
	Button btnnormal;
	double deslat1;
	double deslng1;
	SQLiteDatabase db;
	double[] test = new double[19];
	int i = 0;
	int j = 0;
	double min;
	Button startvoicere;
	Boolean clickk = false;
	int a = 1;
	TextView textmai;
	String UserID;

   
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		
		
	
	try {
			SQLiteforSMS sql = new SQLiteforSMS(this);
			sql.getWritableDatabase();
			long flg1 = sql.InsertData(1, 14.07431, 100.594742,
					"0882365901");
			Log.d("sql", "" + flg1);
			if (flg1 > 0) {
				Toast.makeText(MainActivity.this,
						"Insert(1) Data Successfully", Toast.LENGTH_LONG)
						.show();
			} else {
				Toast.makeText(MainActivity.this, "Insert(1) Data Failed.",
						Toast.LENGTH_LONG).show();
			}

			long flg2 = sql.InsertData(2, 14.120262, 100.976002,
					"0882365901");
			Log.d("sql", "" + flg1);
			if (flg2 > 0) {
				Toast.makeText(MainActivity.this,
						"Insert(2) Data Successfully", Toast.LENGTH_LONG)
						.show();
			} else {
				Toast.makeText(MainActivity.this, "Insert(2) Data Failed.",
						Toast.LENGTH_LONG).show();
			}

			long flg3 = sql.InsertData(3, 14.036386, 100.727565,
					"0882365901");
			// 14.036386,100.727565
			Log.d("sql", "" + flg1);
			if (flg3 > 0) {
				Toast.makeText(MainActivity.this,
						"Insert(3) Data Successfully", Toast.LENGTH_LONG)
						.show();
			} else {
				Toast.makeText(MainActivity.this, "Insert(3) Data Failed.",
						Toast.LENGTH_LONG).show();
			}

		} catch (SQLException sql) {
			// TODO: handle exception
			sql.printStackTrace();
		}
	
		
		SQLiteforUserID sql1 = new SQLiteforUserID(this);
		sql1.getWritableDatabase();
		List<UserIDMember> MemUser = sql1.SelectData();
		for (UserIDMember mem : MemUser) {
			Toast.makeText(
					MainActivity.this,
					"MemberID = " + mem.getid()+ ", UserID = "+ mem.get_userid(),
					Toast.LENGTH_LONG).show();
			if (mem != null) {
				UserID = mem.get_userid();

			}
		}
	
		if (UserID == null) {
			
			Toast.makeText(MainActivity.this,
					"Not found Data!", Toast.LENGTH_LONG)
					.show();		
			Intent gonext = new Intent(getBaseContext(),Register.class);
			startActivity(gonext);	
			
		} else {

			Intent gonextt = new Intent(getBaseContext(),NotNullUserID.class);
			startActivity(gonextt);
		   
		}	
	}
}
